package com.linkoog.devtools.http.toolwindow.workbenche.left.http_service;

import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.linkoog.devtools.intellij.ui.tree.TreeBaseNode;
import com.linkoog.devtools.utils.StringUtils;
import jdk.jfr.Description;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;

/**
 */
@Description("树形结点展示内容自定义渲染器")
public class HttpServiceTreeCellRenderer extends ColoredTreeCellRenderer {
    @Override
    public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        if (value instanceof TreeBaseNode node) {
            setIcon(node.getIcon());
            append(node.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
            String description = node.getDescription();
            if (StringUtils.isNotEmpty(description)) {
                setToolTipText(description);
            }
        }
    }
}
